package com.mall.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.mapper.OrderDetailMapper;
import com.mall.mapper.OrderMapper;
import com.mall.pojo.Order;
import com.mall.pojo.OrderDetail;
import com.mall.service.IOrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiao-chen
 * @since 2023-05-06
 */
@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderDetailMapper orderDetailMapper;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void payUpdateStatus(List<OrderDetail> list,Integer status) {
        orderMapper.payUpdateStatus(list.get(0).getOrderId(),status);
        list.forEach(orderDetail -> orderDetailMapper.payUpdateStatus(orderDetail.getId(),status));

    }


}
